from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-05 14:02:41.663695
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 05, Dec, 2022
Time: 14:02:49
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.1434
Nobs: 861.000 HQIC: -51.4504
Log likelihood: 11326.0 FPE: 3.73845e-23
AIC: -51.6408 Det(Omega_mle): 3.36943e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300346 0.050040 6.002 0.000
L1.Burgenland 0.110392 0.034387 3.210 0.001
L1.Kärnten -0.104306 0.018339 -5.688 0.000
L1.Niederösterreich 0.209369 0.071894 2.912 0.004
L1.Oberösterreich 0.099966 0.068220 1.465 0.143
L1.Salzburg 0.248553 0.036269 6.853 0.000
L1.Steiermark 0.037361 0.047772 0.782 0.434
L1.Tirol 0.109067 0.038775 2.813 0.005
L1.Vorarlberg -0.059714 0.033417 -1.787 0.074
L1.Wien 0.053172 0.061030 0.871 0.384
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.068898 0.103154 0.668 0.504
L1.Burgenland -0.029584 0.070887 -0.417 0.676
L1.Kärnten 0.049596 0.037806 1.312 0.190
L1.Niederösterreich -0.174145 0.148207 -1.175 0.240
L1.Oberösterreich 0.374839 0.140633 2.665 0.008
L1.Salzburg 0.288439 0.074767 3.858 0.000
L1.Steiermark 0.108282 0.098480 1.100 0.272
L1.Tirol 0.317814 0.079932 3.976 0.000
L1.Vorarlberg 0.023872 0.068888 0.347 0.729
L1.Wien -0.021752 0.125811 -0.173 0.863
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198060 0.025906 7.645 0.000
L1.Burgenland 0.092716 0.017802 5.208 0.000
L1.Kärnten -0.008447 0.009494 -0.890 0.374
L1.Niederösterreich 0.267229 0.037220 7.180 0.000
L1.Oberösterreich 0.114685 0.035318 3.247 0.001
L1.Salzburg 0.053083 0.018777 2.827 0.005
L1.Steiermark 0.017458 0.024732 0.706 0.480
L1.Tirol 0.098772 0.020074 4.920 0.000
L1.Vorarlberg 0.056039 0.017301 3.239 0.001
L1.Wien 0.111456 0.031596 3.528 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105794 0.026600 3.977 0.000
L1.Burgenland 0.047981 0.018279 2.625 0.009
L1.Kärnten -0.016359 0.009749 -1.678 0.093
L1.Niederösterreich 0.196095 0.038218 5.131 0.000
L1.Oberösterreich 0.280233 0.036265 7.727 0.000
L1.Salzburg 0.119239 0.019280 6.185 0.000
L1.Steiermark 0.101108 0.025395 3.981 0.000
L1.Tirol 0.123984 0.020612 6.015 0.000
L1.Vorarlberg 0.069070 0.017764 3.888 0.000
L1.Wien -0.028043 0.032443 -0.864 0.387
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131255 0.048225 2.722 0.006
L1.Burgenland -0.051697 0.033140 -1.560 0.119
L1.Kärnten -0.036808 0.017674 -2.083 0.037
L1.Niederösterreich 0.171305 0.069287 2.472 0.013
L1.Oberösterreich 0.133811 0.065746 2.035 0.042
L1.Salzburg 0.288875 0.034954 8.264 0.000
L1.Steiermark 0.034273 0.046040 0.744 0.457
L1.Tirol 0.161805 0.037369 4.330 0.000
L1.Vorarlberg 0.106649 0.032206 3.312 0.001
L1.Wien 0.062167 0.058817 1.057 0.291
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059148 0.038104 1.552 0.121
L1.Burgenland 0.042643 0.026185 1.629 0.103
L1.Kärnten 0.050445 0.013965 3.612 0.000
L1.Niederösterreich 0.226786 0.054746 4.143 0.000
L1.Oberösterreich 0.273027 0.051948 5.256 0.000
L1.Salzburg 0.058237 0.027618 2.109 0.035
L1.Steiermark -0.007040 0.036377 -0.194 0.847
L1.Tirol 0.155834 0.029526 5.278 0.000
L1.Vorarlberg 0.068451 0.025447 2.690 0.007
L1.Wien 0.073088 0.046473 1.573 0.116
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186510 0.045531 4.096 0.000
L1.Burgenland -0.006739 0.031289 -0.215 0.829
L1.Kärnten -0.061739 0.016687 -3.700 0.000
L1.Niederösterreich -0.088149 0.065417 -1.348 0.178
L1.Oberösterreich 0.192040 0.062074 3.094 0.002
L1.Salzburg 0.060612 0.033001 1.837 0.066
L1.Steiermark 0.225372 0.043468 5.185 0.000
L1.Tirol 0.498076 0.035281 14.117 0.000
L1.Vorarlberg 0.048574 0.030406 1.597 0.110
L1.Wien -0.052488 0.055531 -0.945 0.345
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160053 0.051971 3.080 0.002
L1.Burgenland -0.007754 0.035714 -0.217 0.828
L1.Kärnten 0.066591 0.019047 3.496 0.000
L1.Niederösterreich 0.199784 0.074670 2.676 0.007
L1.Oberösterreich -0.066697 0.070854 -0.941 0.347
L1.Salzburg 0.221071 0.037669 5.869 0.000
L1.Steiermark 0.114061 0.049616 2.299 0.022
L1.Tirol 0.083975 0.040272 2.085 0.037
L1.Vorarlberg 0.122964 0.034707 3.543 0.000
L1.Wien 0.107614 0.063386 1.698 0.090
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357235 0.030665 11.650 0.000
L1.Burgenland 0.009044 0.021072 0.429 0.668
L1.Kärnten -0.024233 0.011238 -2.156 0.031
L1.Niederösterreich 0.226950 0.044057 5.151 0.000
L1.Oberösterreich 0.157900 0.041806 3.777 0.000
L1.Salzburg 0.052462 0.022226 2.360 0.018
L1.Steiermark -0.016554 0.029275 -0.565 0.572
L1.Tirol 0.116748 0.023761 4.913 0.000
L1.Vorarlberg 0.072043 0.020478 3.518 0.000
L1.Wien 0.049844 0.037400 1.333 0.183
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043768 0.160720 0.191564 0.163662 0.132173 0.126079 0.070866 0.231062
Kärnten 0.043768 1.000000 0.002102 0.132069 0.026270 0.098953 0.428817 -0.050119 0.101917
Niederösterreich 0.160720 0.002102 1.000000 0.344098 0.168427 0.310616 0.128630 0.192607 0.341886
Oberösterreich 0.191564 0.132069 0.344098 1.000000 0.233454 0.340139 0.176224 0.179953 0.273968
Salzburg 0.163662 0.026270 0.168427 0.233454 1.000000 0.152019 0.133876 0.152752 0.141438
Steiermark 0.132173 0.098953 0.310616 0.340139 0.152019 1.000000 0.162185 0.148173 0.093410
Tirol 0.126079 0.428817 0.128630 0.176224 0.133876 0.162185 1.000000 0.123549 0.166254
Vorarlberg 0.070866 -0.050119 0.192607 0.179953 0.152752 0.148173 0.123549 1.000000 0.020383
Wien 0.231062 0.101917 0.341886 0.273968 0.141438 0.093410 0.166254 0.020383 1.000000